package xyz.weizhi;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author milian
 * @Date 2021/9/5 0005 14:26
 */
public class proxyInvocationHandler implements InvocationHandler {
    // 被代理的接口
    private Object target;

    public void setRent(Object target) {
        this.target = target;
    }
    // 生成代理类
    public Object getProxy(){
        return Proxy.newProxyInstance(this.getClass().getClassLoader(), target.getClass().getInterfaces(),this);
    }
    //处理代理实例，并返回结果
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = method.invoke(target, args);
        return result;
    }
}
